/*
 * Context.cpp
 *
 *  Created on: 03.12.2012
 *      Author: zheka
 */

#include "Context.hpp"
#include "EventDispatcher.hpp"
#include "Task.hpp"
#include <algorithm>
#include <unistd.h>
Context::Context(EventDispatcher * dispatcher, Task * task) :
		dispatcher(dispatcher), task(task) {

}

void Context::enableRead() {
	dispatcher->selectEvent.getReadSet().set(task->getFileDiscriptor());
}

void Context::disableRead() {
	dispatcher->selectEvent.getReadSet().clear(task->getFileDiscriptor());
}

void Context::enableWrite() {
	dispatcher->selectEvent.getWriteSet().set(task->getFileDiscriptor());
}

void Context::disableWrite() {
	fsync(task->getFileDiscriptor());
	dispatcher->selectEvent.getWriteSet().clear(task->getFileDiscriptor());
}

void Context::unregister() {
	fsync(task->getFileDiscriptor());
	dispatcher->removeTask(task);
}

void Context::registerNewTask(Task * task) {
	dispatcher->addTask(task);
}

